package com.qm.console.component.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
import org.springframework.transaction.support.TransactionCallback;
import org.springframework.transaction.support.TransactionTemplate;

import javax.annotation.PostConstruct;

/**
 * @author fangzhipeng
 * @date 2017/12/18
 */
@Component
public class Tx {

    private static TransactionTemplate transactionTemplate;

    @Autowired
    private ApplicationContext applicationContext;

    public static <T> T excuate(TransactionCallback<T> action) {
        return transactionTemplate.execute(action);
    }

    @PostConstruct
    void init() {
        // transactionTemplate = applicationContext.getBean(TransactionTemplate.class);
    }
}
